package com.zzgele.qmzb.api.web;

import com.alibaba.boot.dubbo.annotation.DubboConsumer;
import com.github.pagehelper.PageInfo;
import com.zzgele.qmzb.api.core.Result;
import com.zzgele.qmzb.api.core.ResultGenerator;
import com.zzgele.qmzb.api.model.Notice;
import com.zzgele.qmzb.api.model.UserLog;
import com.zzgele.qmzb.api.service.NoticeService;
import com.zzgele.qmzb.api.utils.PageUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tk.mybatis.mapper.entity.Condition;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
* Created by Martin on 2017/07/13.
*/
@RestController
@RequestMapping("/public")
public class NoticeController {
    private final Logger logger = LoggerFactory.getLogger(NoticeController.class);

    @DubboConsumer
    private NoticeService noticeService;

    @RequestMapping("/notice/list")
    public Result list(Integer channelId, Integer page, Integer page_size ){
        if(channelId==null){
            channelId=1;
        }
        if(page==null)
            page=1;
        if(page_size==null){
            page_size=10;
        }
        PageUtil.startPage(page, page_size);
        Condition condition=new Condition(UserLog.class);
        condition.createCriteria().andCondition("channel_id=" + channelId );
        condition.setOrderByClause("seq_no asc");
        List<Notice> list = noticeService.findByCondition(condition);
        HashMap videoListHashMap = PageUtil.getPageInfoHashMap(new PageInfo(list));

        return ResultGenerator.genSuccessResult(videoListHashMap);
    }

}
